package com.toledo.salao.funcionario;

import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.toledo.salao.funcao.Funcao;
import com.toledo.salao.pessoa.Pessoa;
import com.toledo.salao.servico.Servico;


@Entity
@Table(name = "funcionario")
public class Funcionario extends Pessoa {
	
	public Funcionario() {
	
	}
	
	//@Id
	@GeneratedValue (strategy = GenerationType.AUTO)
	private Integer id_funcionario;
	
	private  String nivel;
	
	
	@ManyToMany
	  @JoinTable(
	      name="FUNC_SERV",
	      joinColumns={@JoinColumn(name="id_pessoa", referencedColumnName="id_pessoa")},
	      inverseJoinColumns={@JoinColumn(name="id_servico", referencedColumnName="id_servico")})
	private Collection<Servico> servicos;
	
	public Collection<Servico> getServicos() {
		return servicos;
	}

	public void setServicos(Collection<Servico> servicos) {
		this.servicos = servicos;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((funcao == null) ? 0 : funcao.hashCode());
		result = prime * result
				+ ((id_funcionario == null) ? 0 : id_funcionario.hashCode());
		result = prime * result + ((nivel == null) ? 0 : nivel.hashCode());
		result = prime * result
				+ ((servicos == null) ? 0 : servicos.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Funcionario other = (Funcionario) obj;
		if (funcao == null) {
			if (other.funcao != null)
				return false;
		} else if (!funcao.equals(other.funcao))
			return false;
		if (id_funcionario == null) {
			if (other.id_funcionario != null)
				return false;
		} else if (!id_funcionario.equals(other.id_funcionario))
			return false;
		if (nivel == null) {
			if (other.nivel != null)
				return false;
		} else if (!nivel.equals(other.nivel))
			return false;
		if (servicos == null) {
			if (other.servicos != null)
				return false;
		} else if (!servicos.equals(other.servicos))
			return false;
		return true;
	}


	@ManyToOne
	@JoinColumn(name="id_funcao")
	private Funcao funcao;
	
	public Funcionario(String nivel, Funcao funcao, Collection<Servico> servicos ) {
		super();
		this.nivel = nivel;
		this.funcao = funcao;
		this.servicos = servicos;
		
		
			}
	
	public Funcao getFuncao() {
		return funcao;
	}

	public void setFuncao(Funcao funcao) {
		this.funcao = funcao;
	}

	public Integer getId_funcionario() {
		return id_funcionario;
	}
	
	public void setId_funcionario(Integer id_funcionario) {
		this.id_funcionario = id_funcionario;
	}
	
	public String getNivel() {
		return nivel;
	}

	public void setNivel(String nivel) {
		this.nivel = nivel;
	}


}
